package jam.objects {
	import org.flixel.FlxG;
	import org.flixel.FlxSound;
	import jam.registry.Resource;
	import org.flixel.FlxSprite;

	/**
	 * @author oati
	 */
	public class Exit extends FlxSprite {
		
		private var shutSound:FlxSound;
		
		public function Exit(X : Number = 0, Y : Number = 0, SimpleGraphic : Class = null, finalLevel:Boolean = false) {
			super(X*Game.TILE_SIZE, Y*Game.TILE_SIZE - 8);
			loadGraphic(Resource.EXIT, true, false, 12, 16);
    		addAnimation("goThrough", [1, 1, 1, 1, 1, 2, 3, 4, 4, 4, 4, 5, 6, 0], 8, false);
			addAnimation("comeOut", [0, 7, 6, 5, 4, 3, 2, 1, 1], 8, false);
    		addAnimation("closed", [0], 0, false);
			addAnimationCallback(handleAnimationChanged); 
			this.immovable = true;
			width = 1;
			centerOffsets();
			play("closed");
			
			shutSound = new FlxSound();
			shutSound.loadEmbedded(Resource.DOOR_CLOSE);
		}
		
		private function handleAnimationChanged(name:String, frameNumber:uint, frameIndex:uint):void
		{
			if (visible) {
				if ((name == "goThrough" && frameNumber == 8))
				{
					shutSound.play();
				}
			}
		}
	}
}
